unit U_fm_add_item;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.Buttons, Vcl.DBCtrls,
  Vcl.ExtCtrls, Vcl.Mask;

type
  Tfm_add_item = class(TForm)
    Panel1: TPanel;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    btn_localizar_item: TSpeedButton;
    Label29: TLabel;
    Label5: TLabel;
    BitBtn1: TBitBtn;
    BitBtn2: TBitBtn;
    Label10: TLabel;
    DBText1: TDBText;
    Label8: TLabel;
    Edittotal: TEdit;
    Label6: TLabel;
    Label7: TLabel;
    Label9: TLabel;
    Editcod: TEdit;
    Editdescricao: TEdit;
    Editund: TEdit;
    Editquant: TEdit;
    Editvalor: TEdit;
    Editdesc: TEdit;
    procedure btn_localizar_itemClick(Sender: TObject);
    procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
    procedure edt_id_itemKeyUp(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure BitBtn1Click(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure DBEdit2Change(Sender: TObject);
    procedure BitBtn2Click(Sender: TObject);
    procedure DBEdit4Exit(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
     procedure limpar;
  end;

var
  fm_add_item: Tfm_add_item;

implementation

{$R *.dfm}

uses U_fm_pesq_item, U_dm_principal;

procedure Tfm_add_item.BitBtn1Click(Sender: TObject);
begin
dm_principal.cds_item.Insert;
dm_principal.sq_generators.Close;
dm_principal.sq_generators.SQL.Text:='select gen_id(GEN_ITEM_ID,1)as id from Rdb$database';
dm_principal.sq_generators.Open;
dm_principal.cds_itemID.Value:=dm_principal.sq_generators.FieldByName('id').AsInteger;

dm_principal.cds_itemNFE.AsInteger:=dm_principal.cds_entradaN_NFE.AsInteger;
dm_principal.cds_itemPRODUTO.AsString:= Editdescricao.Text;
dm_principal.cds_itemUN.AsString:= Editund.Text;
dm_principal.cds_itemPRECO_CUSTO.AsString:= Editvalor.Text;
dm_principal.cds_itemTOTAL_NOTA2.AsString:= Edittotal.Text;
dm_principal.cds_itemDESCONTO.AsString:= Editdesc.Text;
dm_principal.cds_itemQUANTIDADE_ITEM.AsString:= Editquant.Text;
dm_principal.cds_itemCODIGO_PRODUTO.AsString:= Editcod.Text;
dm_principal.cds_item.Post;
dm_principal.cds_item.ApplyUpdates(0);
limpar;


end;

procedure Tfm_add_item.BitBtn2Click(Sender: TObject);
begin
Close;
end;

procedure Tfm_add_item.btn_localizar_itemClick(Sender: TObject);
begin
fm_pesq_item:=Tfm_pesq_item.Create(Application);
fm_pesq_item.ShowModal;
 if fm_pesq_item.ModalResult=mrok then
 begin
   //edt_id_item.Text:=dm_principal.cds_produtoCODIGO_ITEM.Text;
   //edit1.Text:=dm_principal.cds_produtoDESCRICAO.Text;
 end;
end;

procedure Tfm_add_item.DBEdit2Change(Sender: TObject);
begin
  //label do total
  //lbl_total.caption :=FormatFLoat('#,##0.00',(dm_principal.cds_saidaQUANTIDADE.asfloat * (dm_principal.cds_saidaVALOR_UNI.AsFloat)));
  //lbl_total.Repaint;
end;

procedure Tfm_add_item.DBEdit4Exit(Sender: TObject);
begin
   // Edit1.Text := FloatToStr( StrToFloat( DBEdit2.Text ) * StrToFloat( DBEdit4.Text )- StrToFloat( DBEdit5.Text ) );
end;

procedure Tfm_add_item.edt_id_itemKeyUp(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
if key = VK_F2 then
   btn_localizar_itemClick(Self);
end;

procedure Tfm_add_item.FormKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
// if Key=vk_f2 then btn_localizar_item.Click;
end;

procedure Tfm_add_item.FormShow(Sender: TObject);
begin
dm_principal.cds_item.Open;
end;
procedure Tfm_add_item.limpar;

  begin
     with fm_add_item do

    Editcod.text:='';
    Edittotal.text:='';
    Editdescricao.text:='';
    Editund.text:='';
    Editquant.Text:='';
    Editvalor.Text:='';
    Editdesc.Text:='';


end;
end.
